package com.hsnn.medstgmini.pro.base.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.model.DicSys;
import com.hsnn.medstgmini.base.std.model.Classify;
import com.hsnn.medstgmini.base.std.model.CompClassify;
import com.hsnn.medstgmini.base.std.model.HospInfo;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.pro.base.model.BaseGoods;
import com.hsnn.medstgmini.pro.base.service.BaseGoodsByHospManager;
import com.hsnn.medstgmini.pro.project.service.BidProjectManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.DicSysUtil;
import com.hsnn.medstgmini.util.Pagination;

@Controller
@RequestMapping("/proBaseGoods")
public class BaseGoodsByHospController {
	@Autowired
	private BaseGoodsByHospManager baseGoodsManager;
	@Autowired
	private BidProjectManager bidProjectManager;
	@Autowired
	private HttpServletRequest request;

	/**
	 * @category 进入医疗机构商品列表页面
	 * @auth 陈镜宇
	 * @param model
	 * @param bidProject
	 * @return
	 * @date 2015年6月15日
	 */
	@RequestMapping("/toBaseGoodsList")
	public String toUnBidProjectDrugsList(Model model) {
		SysUser user = (SysUser) request.getSession().getAttribute(
				Constants.USERINFO);
		String url = "";
		if (user.getType() == 4) { // 医院
			List<DicSys> mlist = DicSysUtil.getDicListByClassCode(Constants.PRO_METHOD);
			/*if(mlist != null){
				for(int i=0;i<mlist.size();i++){
					if( Constants.GOODS_SOURCE_BJBX == Integer.valueOf(mlist.get(i).getDicCode())){
						mlist.get(i).setDicName("");
					}
				}
			}*/
			request.setAttribute("list", mlist);
			
			url = "/pro/base/baseGoodsListByHosp";
		} else if (user.getType() == 2) { // 生产
			url = "/pro/base/baseGoodsListByComp";
		} else if (user.getType() == 3) {// 配送
			url = "/pro/base/baseGoodsListByTransComp";
		}
		return url;
	}

	/**
	 * 
	 * @category 生产企业查询商品目录
	 * @param projId
	 * @return
	 * @date 2015年6月11日
	 */
	@ResponseBody
	@RequestMapping("/getBaseGoodsListJsonByComp")
	public Pagination getBaseGoodsListJsonByComp(BaseGoods form) {
		Pagination page = new Pagination(request);
		SysUser user = (SysUser) request.getSession().getAttribute(
				Constants.USERINFO);
		StdCompinfo compInfo = user.getInfo();
		form.setCompCode(compInfo.getCompCode());
		page.setForm(form);
		return baseGoodsManager.getBaseGoodsListJsonByComp(page);
	}

	/**
	 * 
	 * @category 配送企业查询商品目录
	 * @author 邱磊
	 * @date 2015年8月7日 上午10:57:31
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getBaseGoodsListJsonByDel")
	public Pagination getBaseGoodsListJsonByDel(BaseGoods form) {
		Pagination page = new Pagination(request);
		SysUser user = (SysUser) request.getSession().getAttribute(
				Constants.USERINFO);
		StdCompinfo compInfo = user.getInfo();
		form.setCompCode(compInfo.getCompCode());
		page.setForm(form);
		return baseGoodsManager.getBaseGoodsListJsonByDel(page);
	}

	/**
	 * 医院获取商品目录列表Json
	 * 
	 * @category param projId
	 * @return
	 * @date 2015年6月11日
	 */
	@ResponseBody
	@RequestMapping("/getBaseGoodsListJsonByHosp")
	public Pagination getBaseGoodsListJsonByHosp(BaseGoods form) {
		Pagination page = new Pagination(request);
		SysUser user = (SysUser) request.getSession().getAttribute(Constants.USERINFO);
		HospInfo hospInfo = user.getInfo();
		form.setHospCode(hospInfo.getHospCode());
		page.setForm(form);
		return baseGoodsManager.getBaseGoodsListByHosp(page, hospInfo);
	}
	
}